<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div>sdfdfsdfsdf</div>
  <script>
    function Person(name, age) {
      this.name = name;
      this.age = age;
    }
    function rewriteNew(sup, ...param) {
      //1.创建新对象
      var obj = {};
      //2.将空对象作为 this，调用构造函数并传入参数
      var result = sup.call(obj, ...param);
      //3.将该对象__proto__指向构造函数原型对象，实现继承
      obj.__proto__ = sup.prototype;//Object.setPrototypeOf(obj,sup.prototype)
      //4.如果构造函数返回值为对象或者函数，则返回该对象或者函数，否则返回创建的新对象obj
      return typeof result === "object" || typeof result === "function" ? result : obj
    };
    let a = rewriteNew(Person, 'baoye', 18)
  </script>

  <script>
    Function.prototype.mcall = function(ctx,...args){
      let func = this
      let funcname = Symbol()
      ctx[funcname] = func
      ctx[funcname](...args)
      delete ctx[funcname]
    }
  </script>
</body>

</html>